"""
DAQ125设备Python绑定
封装DAQ125设备的C接口函数
"""

import ctypes
from typing import List, Optional, Tuple
from .base_device_binding import BaseDeviceBinding


class DAQ125Binding(BaseDeviceBinding):
    """DAQ125设备Python绑定类"""
    
    def __init__(self, dll_path: str):
        """
        初始化DAQ125设备绑定
        
        Args:
            dll_path: DLL文件路径
        """
        super().__init__(dll_path)
        self._setup_daq125_function_signatures()
    
    def _setup_daq125_function_signatures(self):
        """设置DAQ125特有的函数签名"""
        # 设备生命周期管理
        self.dll.DAQ125_New.argtypes = []
        self.dll.DAQ125_New.restype = ctypes.POINTER(ctypes.c_uint32)
        
        self.dll.DAQ125_Delete.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_Delete.restype = None
        
        # 设备连接和初始化
        self.dll.DAQ125_UseBackend.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_uint32)
        ]
        self.dll.DAQ125_UseBackend.restype = ctypes.c_bool
        
        self.dll.DAQ125_InitializeDevice.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_InitializeDevice.restype = ctypes.c_bool
        
        self.dll.DAQ125_ConnectedDevice.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_ConnectedDevice.restype = ctypes.c_bool
        
        self.dll.DAQ125_DisconnectedDevice.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_DisconnectedDevice.restype = ctypes.c_bool
        
        # ADC配置函数
        self.dll.DAQ125_ConfigADCTrigger.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int
        ]
        self.dll.DAQ125_ConfigADCTrigger.restype = ctypes.c_bool
        
        self.dll.DAQ125_ConfigADCSampleRate.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_int
        ]
        self.dll.DAQ125_ConfigADCSampleRate.restype = ctypes.c_bool
        
        self.dll.DAQ125_ConfigADCVoltage.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_int
        ]
        self.dll.DAQ125_ConfigADCVoltage.restype = ctypes.c_bool
        
        self.dll.DAQ125_ConfigADCVoltage_Batch.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_int), 
            ctypes.c_int
        ]
        self.dll.DAQ125_ConfigADCVoltage_Batch.restype = ctypes.c_bool
        
        self.dll.DAQ125_ConfigADCTriggerLength.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_uint32
        ]
        self.dll.DAQ125_ConfigADCTriggerLength.restype = ctypes.c_bool
        
        self.dll.DAQ125_ConfigTriggerTimeout.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_uint32
        ]
        self.dll.DAQ125_ConfigTriggerTimeout.restype = ctypes.c_bool
        
        self.dll.DAQ125_ConfigADCChannel.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_uint8
        ]
        self.dll.DAQ125_ConfigADCChannel.restype = ctypes.c_bool
        
        self.dll.DAQ125_ConfigADCChannel_Batch.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_bool), 
            ctypes.c_int
        ]
        self.dll.DAQ125_ConfigADCChannel_Batch.restype = ctypes.c_bool
        
        self.dll.DAQ125_ConfigACDC.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_uint8
        ]
        self.dll.DAQ125_ConfigACDC.restype = ctypes.c_bool
        
        # 触发源配置函数
        self.dll.DAQ125_ConfigADCTriggerSource.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_ConfigADCTriggerSource.restype = ctypes.c_bool
        
        # 数据采集控制
        self.dll.DAQ125_StartCollection.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_StartCollection.restype = ctypes.c_bool
        
        self.dll.DAQ125_StopCollection.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_StopCollection.restype = ctypes.c_bool
        
        # 数据读取函数
        self.dll.DAQ125_TryReadData.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_uint8, 
            ctypes.POINTER(ctypes.c_float), 
            ctypes.c_uint32, 
            ctypes.c_uint32
        ]
        self.dll.DAQ125_TryReadData.restype = ctypes.c_bool
        
        self.dll.DAQ125_TryReadData_Point.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_uint8, 
            ctypes.POINTER(ctypes.c_float)
        ]
        self.dll.DAQ125_TryReadData_Point.restype = ctypes.c_bool
        
        self.dll.DAQ125_TryReadData_Batch.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_uint8, 
            ctypes.POINTER(ctypes.c_float), 
            ctypes.c_uint32
        ]
        self.dll.DAQ125_TryReadData_Batch.restype = ctypes.c_bool
        
        # 缓冲区管理
        self.dll.DAQ125_ClearDataBuffer.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_ClearDataBuffer.restype = ctypes.c_bool
        
        self.dll.DAQ125_ClearDataBuffer_Channel.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_uint8
        ]
        self.dll.DAQ125_ClearDataBuffer_Channel.restype = ctypes.c_bool
        
        # 设备信息获取
        self.dll.DAQ125_GetSN.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_char_p, 
            ctypes.c_int
        ]
        self.dll.DAQ125_GetSN.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetDeviceName.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_char_p, 
            ctypes.c_int
        ]
        self.dll.DAQ125_GetDeviceName.restype = ctypes.c_bool
        
        # 版本信息获取
        self.dll.DAQ125_GetDeviceType.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_char_p, 
            ctypes.c_int
        ]
        self.dll.DAQ125_GetDeviceType.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetHardwareVersion.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_char_p, 
            ctypes.c_int
        ]
        self.dll.DAQ125_GetHardwareVersion.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetBootLoaderVersion.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_char_p, 
            ctypes.c_int
        ]
        self.dll.DAQ125_GetBootLoaderVersion.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetSoftwareVersion.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_char_p, 
            ctypes.c_int
        ]
        self.dll.DAQ125_GetSoftwareVersion.restype = ctypes.c_bool
        
        # ADC参数获取
        self.dll.DAQ125_GetCurrentSampleRate.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_GetCurrentSampleRate.restype = ctypes.c_uint32
        
        self.dll.DAQ125_GetADCLegalChannelSize.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_GetADCLegalChannelSize.restype = ctypes.c_uint8
        
        self.dll.DAQ125_GetADCBufferDataSize.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_int
        ]
        self.dll.DAQ125_GetADCBufferDataSize.restype = ctypes.c_uint32
        
        self.dll.DAQ125_GetChannelEnableState.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_GetChannelEnableState.restype = ctypes.c_uint8
        
        # 参数验证函数
        self.dll.DAQ125_ADCSampleRateIsLegal.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_uint32
        ]
        self.dll.DAQ125_ADCSampleRateIsLegal.restype = ctypes.c_bool
        
        self.dll.DAQ125_ADCRangeIsLegal.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.c_int
        ]
        self.dll.DAQ125_ADCRangeIsLegal.restype = ctypes.c_bool
        
        # 新增函数签名
        self.dll.DAQ125_GetADCLegalSampleRate.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_int)
        ]
        self.dll.DAQ125_GetADCLegalSampleRate.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetADCBufferDataMaxSize.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_GetADCBufferDataMaxSize.restype = ctypes.c_uint32
        
        self.dll.DAQ125_GetADCLegalLengthMin.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_GetADCLegalLengthMin.restype = ctypes.c_uint32
        
        self.dll.DAQ125_GetADCLegalLengthMax.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
        self.dll.DAQ125_GetADCLegalLengthMax.restype = ctypes.c_uint32
        
        self.dll.DAQ125_GetADCLegalChannel.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_int)
        ]
        self.dll.DAQ125_GetADCLegalChannel.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetADCLegalVoltage.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_int)
        ]
        self.dll.DAQ125_GetADCLegalVoltage.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetCurrentTriggerType.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_uint32)
        ]
        self.dll.DAQ125_GetCurrentTriggerType.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetCurrentTriggerMode.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_uint32)
        ]
        self.dll.DAQ125_GetCurrentTriggerMode.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetChannelEnableList.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_bool), 
            ctypes.POINTER(ctypes.c_int)
        ]
        self.dll.DAQ125_GetChannelEnableList.restype = ctypes.c_bool
        
        self.dll.DAQ125_GetADCCurrentVoltage.argtypes = [
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_uint32), 
            ctypes.POINTER(ctypes.c_int)
        ]
        self.dll.DAQ125_GetADCCurrentVoltage.restype = ctypes.c_bool
    
    def create_device(self) -> Optional[ctypes.POINTER(ctypes.c_uint32)]:
        """
        创建DAQ125设备实例
        
        Returns:
            设备句柄，失败返回None
        """
        handle = self.dll.DAQ125_New()
        return handle if handle else None
    
    def delete_device(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> None:
        """
        删除DAQ125设备实例
        
        Args:
            handle: 设备句柄
        """
        if handle:
            self.dll.DAQ125_Delete(handle)
    
    def use_backend(self, device_handle: ctypes.POINTER(ctypes.c_uint32), 
                    backend_handle: ctypes.POINTER(ctypes.c_uint32)) -> bool:
        """
        设置设备使用的后端
        
        Args:
            device_handle: 设备句柄
            backend_handle: 后端句柄
            
        Returns:
            是否成功
        """
        if not device_handle or not backend_handle:
            return False
        
        return self.dll.DAQ125_UseBackend(device_handle, backend_handle)
    
    def initialize_device(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> bool:
        """
        初始化设备
        
        Args:
            handle: 设备句柄
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_InitializeDevice(handle)
    
    def connect_device(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> bool:
        """
        连接设备
        
        Args:
            handle: 设备句柄
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ConnectedDevice(handle)
    
    def disconnect_device(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> bool:
        """
        断开设备连接
        
        Args:
            handle: 设备句柄
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_DisconnectedDevice(handle)
    
    def config_adc_trigger(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                          trigger_type: int, trigger_mode: int, 
                          channel: int, level: int) -> bool:
        """
        配置ADC触发参数
        
        Args:
            handle: 设备句柄
            trigger_type: 触发类型
            trigger_mode: 触发模式
            channel: 触发通道
            level: 触发电平
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ConfigADCTrigger(
            handle, trigger_type, trigger_mode, channel, level
        )
    
    def config_adc_sample_rate(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                              sample_rate: int) -> bool:
        """
        配置ADC采样率
        
        Args:
            handle: 设备句柄
            sample_rate: 采样率
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ConfigADCSampleRate(handle, sample_rate)
    
    def config_adc_voltage(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                          voltage: int) -> bool:
        """
        配置ADC电压范围
        
        Args:
            handle: 设备句柄
            voltage: 电压范围
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ConfigADCVoltage(handle, voltage)
    
    def config_adc_voltage_batch(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                                voltage_ranges: List[int]) -> bool:
        """
        批量配置ADC电压范围
        
        Args:
            handle: 设备句柄
            voltage_ranges: 电压范围列表
            
        Returns:
            是否成功
        """
        if not handle or not voltage_ranges:
            return False
        
        # 转换为C数组
        range_array = (ctypes.c_int * len(voltage_ranges))(*voltage_ranges)
        
        return self.dll.DAQ125_ConfigADCVoltage_Batch(
            handle, range_array, len(voltage_ranges)
        )
    
    def config_adc_trigger_length(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                                 data_length: int) -> bool:
        """
        配置ADC触发长度
        
        Args:
            handle: 设备句柄
            data_length: 数据长度
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ConfigADCTriggerLength(handle, data_length)
    
    def config_trigger_timeout(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                              timeout: int) -> bool:
        """
        配置触发超时时间
        
        Args:
            handle: 设备句柄
            timeout: 超时时间
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ConfigTriggerTimeout(handle, timeout)
    
    def config_adc_channel(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                          channel: int) -> bool:
        """
        配置ADC通道
        
        Args:
            handle: 设备句柄
            channel: 通道号
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ConfigADCChannel(handle, channel)
    
    def config_adc_channel_batch(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                                enable_list: List[bool]) -> bool:
        """
        批量配置ADC通道使能状态
        
        Args:
            handle: 设备句柄
            enable_list: 通道使能状态列表
            
        Returns:
            是否成功
        """
        if not handle or not enable_list:
            return False
        
        # 转换为C数组
        enable_array = (ctypes.c_bool * len(enable_list))(*enable_list)
        
        return self.dll.DAQ125_ConfigADCChannel_Batch(
            handle, enable_array, len(enable_list)
        )
    
    def start_collection(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> bool:
        """
        开始数据采集
        
        Args:
            handle: 设备句柄
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_StartCollection(handle)
    
    def stop_collection(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> bool:
        """
        停止数据采集
        
        Args:
            handle: 设备句柄
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_StopCollection(handle)
    
    def try_read_data(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                     channel: int, read_size: int, timeout: int) -> Tuple[bool, List[float]]:
        """
        尝试读取数据
        
        Args:
            handle: 设备句柄
            channel: 通道号
            read_size: 读取数据大小
            timeout: 超时时间
            
        Returns:
            (是否成功, 数据列表)
        """
        if not handle:
            return False, []
        
        # 创建缓冲区
        read_buffer = (ctypes.c_float * read_size)()
        
        success = self.dll.DAQ125_TryReadData(
            handle, channel, read_buffer, read_size, timeout
        )
        
        if success:
            return True, list(read_buffer)
        else:
            return False, []
    
    def try_read_data_point(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                           channel: int) -> Tuple[bool, float]:
        """
        尝试读取单点数据
        
        Args:
            handle: 设备句柄
            channel: 通道号
            
        Returns:
            (是否成功, 数据值)
        """
        if not handle:
            return False, 0.0
        
        read_buffer = ctypes.c_float()
        
        success = self.dll.DAQ125_TryReadData_Point(handle, channel, ctypes.byref(read_buffer))
        
        if success:
            return True, read_buffer.value
        else:
            return False, 0.0
    
    def try_read_data_batch(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                           channel: int, read_size: int) -> Tuple[bool, List[float]]:
        """
        尝试批量读取数据
        
        Args:
            handle: 设备句柄
            channel: 通道号
            read_size: 读取数据大小
            
        Returns:
            (是否成功, 数据列表)
        """
        if not handle:
            return False, []
        
        read_buffer = self._create_float_array(read_size)
        
        success = self.dll.DAQ125_TryReadData_Batch(
            handle, channel, read_buffer, read_size
        )
        
        if success:
            return True, self._convert_float_array_to_list(read_buffer)
        else:
            return False, []
    
    def config_acdc(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                   channel_mask: int) -> bool:
        """
        配置AC/DC耦合
        
        Args:
            handle: 设备句柄
            channel_mask: 通道掩码 (1代表DC，0代表AC)
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ConfigACDC(handle, channel_mask)
    
    def config_adc_trigger_source(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> bool:
        """
        配置ADC触发源（软件触发）
        
        Args:
            handle: 设备句柄
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ConfigADCTriggerSource(handle)
    
    def clear_data_buffer(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> bool:
        """
        清空数据缓冲区
        
        Args:
            handle: 设备句柄
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ClearDataBuffer(handle)
    
    def clear_data_buffer_channel(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                                 channel: int) -> bool:
        """
        清空指定通道的数据缓冲区
        
        Args:
            handle: 设备句柄
            channel: 通道号
            
        Returns:
            是否成功
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ClearDataBuffer_Channel(handle, channel)
    
    def get_device_sn(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> str:
        """
        获取设备序列号
        
        Args:
            handle: 设备句柄
            
        Returns:
            设备序列号
        """
        if not handle:
            return ""
        
        buffer_size = 256
        sn_buffer = ctypes.create_string_buffer(buffer_size)
        
        success = self.dll.DAQ125_GetSN(handle, sn_buffer, buffer_size)
        
        if success:
            return sn_buffer.value.decode('utf-8')
        else:
            return ""
    
    def get_device_name(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> str:
        """
        获取设备名称
        
        Args:
            handle: 设备句柄
            
        Returns:
            设备名称
        """
        if not handle:
            return ""
        
        buffer_size = 256
        name_buffer = ctypes.create_string_buffer(buffer_size)
        
        success = self.dll.DAQ125_GetDeviceName(handle, name_buffer, buffer_size)
        
        if success:
            return name_buffer.value.decode('utf-8')
        else:
            return ""
    
    def get_device_type(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> str:
        """
        获取设备类型
        
        Args:
            handle: 设备句柄
            
        Returns:
            设备类型
        """
        if not handle:
            return ""
        
        buffer_size = 256
        type_buffer = ctypes.create_string_buffer(buffer_size)
        
        success = self.dll.DAQ125_GetDeviceType(handle, type_buffer, buffer_size)
        
        if success:
            return type_buffer.value.decode('utf-8')
        else:
            return ""
    
    def get_hardware_version(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> str:
        """
        获取硬件版本
        
        Args:
            handle: 设备句柄
            
        Returns:
            硬件版本
        """
        if not handle:
            return ""
        
        buffer_size = 256
        version_buffer = ctypes.create_string_buffer(buffer_size)
        
        success = self.dll.DAQ125_GetHardwareVersion(handle, version_buffer, buffer_size)
        
        if success:
            return version_buffer.value.decode('utf-8')
        else:
            return ""
    
    def get_software_version(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> str:
        """
        获取软件版本
        
        Args:
            handle: 设备句柄
            
        Returns:
            软件版本
        """
        if not handle:
            return ""
        
        buffer_size = 256
        version_buffer = ctypes.create_string_buffer(buffer_size)
        
        success = self.dll.DAQ125_GetSoftwareVersion(handle, version_buffer, buffer_size)
        
        if success:
            return version_buffer.value.decode('utf-8')
        else:
            return ""
    
    def get_current_sample_rate(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> int:
        """
        获取当前采样率
        
        Args:
            handle: 设备句柄
            
        Returns:
            当前采样率
        """
        if not handle:
            return 0
        
        return self.dll.DAQ125_GetCurrentSampleRate(handle)
    
    def get_adc_legal_channel_size(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> int:
        """
        获取ADC合法通道数量
        
        Args:
            handle: 设备句柄
            
        Returns:
            通道数量
        """
        if not handle:
            return 0
        
        return self.dll.DAQ125_GetADCLegalChannelSize(handle)
    
    def get_adc_buffer_data_size(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                                channel: int) -> int:
        """
        获取ADC缓冲区数据大小
        
        Args:
            handle: 设备句柄
            channel: 通道号
            
        Returns:
            缓冲区数据大小
        """
        if not handle:
            return 0
        
        return self.dll.DAQ125_GetADCBufferDataSize(handle, channel)
    
    def get_channel_enable_state(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> int:
        """
        获取通道使能状态
        
        Args:
            handle: 设备句柄
            
        Returns:
            通道使能状态位掩码
        """
        if not handle:
            return 0
        
        return self.dll.DAQ125_GetChannelEnableState(handle)
    
    def adc_sample_rate_is_legal(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                                sample_rate: int) -> bool:
        """
        检查ADC采样率是否合法
        
        Args:
            handle: 设备句柄
            sample_rate: 采样率
            
        Returns:
            是否合法
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ADCSampleRateIsLegal(handle, sample_rate)
    
    def adc_range_is_legal(self, handle: ctypes.POINTER(ctypes.c_uint32), 
                          voltage_range: int) -> bool:
        """
        检查ADC电压范围是否合法
        
        Args:
            handle: 设备句柄
            voltage_range: 电压范围
            
        Returns:
            是否合法
        """
        if not handle:
            return False
        
        return self.dll.DAQ125_ADCRangeIsLegal(handle, voltage_range)
    
    def get_adc_legal_sample_rate(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> List[int]:
        """
        获取ADC合法采样率列表
        
        Args:
            handle: 设备句柄
            
        Returns:
            合法采样率列表
        """
        if not handle:
            return []
        
        # 预分配足够大的数组
        max_rates = 50
        rate_array = (ctypes.c_uint32 * max_rates)()
        array_size = ctypes.c_int(max_rates)
        
        success = self.dll.DAQ125_GetADCLegalSampleRate(handle, rate_array, ctypes.byref(array_size))
        
        if success:
            return [rate_array[i] for i in range(array_size.value)]
        else:
            return []
    
    def get_adc_buffer_data_max_size(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> int:
        """
        获取ADC缓冲区最大数据大小
        
        Args:
            handle: 设备句柄
            
        Returns:
            缓冲区最大数据大小
        """
        if not handle:
            return 0
        
        return self.dll.DAQ125_GetADCBufferDataMaxSize(handle)
    
    def get_adc_legal_length_min(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> int:
        """
        获取ADC合法长度最小值
        
        Args:
            handle: 设备句柄
            
        Returns:
            合法长度最小值
        """
        if not handle:
            return 0
        
        return self.dll.DAQ125_GetADCLegalLengthMin(handle)
    
    def get_adc_legal_length_max(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> int:
        """
        获取ADC合法长度最大值
        
        Args:
            handle: 设备句柄
            
        Returns:
            合法长度最大值
        """
        if not handle:
            return 0
        
        return self.dll.DAQ125_GetADCLegalLengthMax(handle)
    
    def get_adc_legal_channel(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> List[int]:
        """
        获取ADC合法通道列表
        
        Args:
            handle: 设备句柄
            
        Returns:
            合法通道列表
        """
        if not handle:
            return []
        
        # 预分配足够大的数组
        max_channels = 32
        channel_array = (ctypes.c_uint32 * max_channels)()
        array_size = ctypes.c_int(max_channels)
        
        success = self.dll.DAQ125_GetADCLegalChannel(handle, channel_array, ctypes.byref(array_size))
        
        if success:
            return [channel_array[i] for i in range(array_size.value)]
        else:
            return []
    
    def get_adc_legal_voltage(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> List[int]:
        """
        获取ADC合法电压范围列表
        
        Args:
            handle: 设备句柄
            
        Returns:
            合法电压范围列表
        """
        if not handle:
            return []
        
        # 预分配足够大的数组
        max_voltages = 32
        voltage_array = (ctypes.c_uint32 * max_voltages)()
        array_size = ctypes.c_int(max_voltages)
        
        success = self.dll.DAQ125_GetADCLegalVoltage(handle, voltage_array, ctypes.byref(array_size))
        
        if success:
            return [voltage_array[i] for i in range(array_size.value)]
        else:
            return []
    
    def get_current_trigger_type(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> int:
        """
        获取当前触发类型
        
        Args:
            handle: 设备句柄
            
        Returns:
            当前触发类型
        """
        if not handle:
            return 0
        
        trigger_type = ctypes.c_uint32()
        success = self.dll.DAQ125_GetCurrentTriggerType(handle, ctypes.byref(trigger_type))
        
        if success:
            return trigger_type.value
        else:
            return 0
    
    def get_current_trigger_mode(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> int:
        """
        获取当前触发模式
        
        Args:
            handle: 设备句柄
            
        Returns:
            当前触发模式
        """
        if not handle:
            return 0
        
        trigger_mode = ctypes.c_uint32()
        success = self.dll.DAQ125_GetCurrentTriggerMode(handle, ctypes.byref(trigger_mode))
        
        if success:
            return trigger_mode.value
        else:
            return 0
    
    def get_channel_enable_list(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> List[bool]:
        """
        获取通道使能状态列表
        
        Args:
            handle: 设备句柄
            
        Returns:
            通道使能状态列表
        """
        if not handle:
            return []
        
        # 预分配足够大的数组
        max_channels = 32
        enable_array = (ctypes.c_bool * max_channels)()
        array_size = ctypes.c_int(max_channels)
        
        success = self.dll.DAQ125_GetChannelEnableList(handle, enable_array, ctypes.byref(array_size))
        
        if success:
            return [bool(enable_array[i]) for i in range(array_size.value)]
        else:
            return []
    
    def get_adc_current_voltage(self, handle: ctypes.POINTER(ctypes.c_uint32)) -> List[int]:
        """
        获取ADC当前电压范围列表
        
        Args:
            handle: 设备句柄
            
        Returns:
            当前电压范围列表
        """
        if not handle:
            return []
        
        # 预分配足够大的数组
        max_voltages = 32
        voltage_array = (ctypes.c_uint32 * max_voltages)()
        array_size = ctypes.c_int(max_voltages)
        
        success = self.dll.DAQ125_GetADCCurrentVoltage(handle, voltage_array, ctypes.byref(array_size))
        
        if success:
            return [voltage_array[i] for i in range(array_size.value)]
        else:
            return [] 